/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package utils;

import java.util.Random;
import java.util.UUID;
import java.util.Vector;

/**
 *
 * @author daz
 */
public class Utils {

    private static Random random = new Random();

    public static String[] split(String source, char delimiter) {

        String tmp;
        Vector v = new Vector();
        int startIndex = 0;
        int idx = source.indexOf(delimiter, startIndex);

        if (idx < 0) {
            //System.out.println("idx < 0");
            return null;
        }

        while (idx >= 0) {
            tmp = source.substring(startIndex, idx).trim();
            if (!tmp.equals("")) {
                v.addElement(tmp);
            }
            startIndex = idx + 1;
            idx = source.indexOf(delimiter, startIndex);
            tmp = null;
        }
        if (v.size() == 0) {
            //System.out.println("v.size() == 0");
            return null;
        }
        tmp = source.substring(source.lastIndexOf(delimiter) + 1, source.length());
        if (!tmp.equals("")) {
            v.addElement(tmp);
        }
        tmp = null;
        String[] r = new String[v.size()];
        for (int i = 0; i < v.size(); i++) {
            r[i] = v.elementAt(i).toString();
        }
        return r;
    }

    public static int nextInt(int limit) {
        return random.nextInt(limit);
    }

    public static int fibonaci(int n) {
        int fchan = 0, fle = 1, i = 1;
        for (i = 3; i <= n; i += 2) {
            fchan = fchan + fle;
            fle = fchan + fle;
        }
        if (n % 2 == 0) {
            return (fchan + fle);
        }
        return fle;
    }

    public static String getPass() {
        String uuid = UUID.randomUUID().toString();
        String pass = uuid.replaceAll("-", "a").substring(0, 6);
        System.out.println("uuid = " + uuid);
        System.out.println("uuid = " + pass);
        return pass;
    }
}
